#ifndef __PSE_CACHEER_H__
#define __PSE_CACHEER_H__
#include <string>
#include "pseHash.h"

using std::string;

/**
 * pse_cacheer_die() prints error message to STDERR, and exits with -1 code.
 */
#define pse_cacheer_die(msg)                                                        \
    do {                                                                \
        fprintf(stderr,                                                 \
                "%s at line %d of file %s\n",                           \
                msg, __LINE__, __FILE__);                               \
        exit(-1);                                                       \
    } while (0)

class PseCacheer{
    protected:
        PseHashTable  self;
        int           expired_seconds;
        unsigned int  cacheer_cache_size;
        unsigned int  cacheer_hash_size;
        int           miss_count;
        int           expired_hit_count;
        int           hit_count;
    
    public:
        PseCacheer();
        ~PseCacheer();
        void          set_expired_seconds(int s);
        bool          init(unsigned int cache_size, unsigned int hash_size);
        int           get_item_count();
        int           get_miss_count();
        int           get_hit_count();
        int           get_expired_hit_count();
        bool          remove(char *key, size_t key_len);
        bool          insert(char *key, size_t key_len, void *value, size_t value_len);
        bool          search(char *key, size_t key_len);
        void         *search_not_remove(char *key, size_t key_len);
        PseHashTable *get_hash_table();
        bool          free_item();        
        bool          dump_file(const char *filename);
        bool          load_file(const char *filename);
        void          report(char *cache_name , char *filename);
        bool          search_in_file(const char *str, size_t str_len, 
                                     const char *filename);
};

#endif
